package com.boyon.system.assembly;

import org.springframework.stereotype.Service;

import com.boyon.common.tree.TreeAssembly;
import com.boyon.system.entity.Menu;

/**
 * ClassName:MenuAssembly <br/>
 * Function: 菜单组件类. <br/>
 * Date: 2018年3月14日 下午11:55:47 <br/>
 * 
 * @author sunshulin
 * @version
 * @since JDK 1.8
 * @see
 */
@Service
public class MenuAssembly extends TreeAssembly<Menu, Long> {

	/**
	 * 创建menu.
	 * 
	 * @see com.boyon.common.tree.TreeAssembly#createT()
	 */
	public Menu createT() {
		Menu m = new Menu();
		m.setLeaf(true);
		return m;
	}

	/**
	 * 获取菜单ID.
	 * 
	 * @see com.boyon.common.tree.TreeAssembly#getId(java.lang.Object)
	 */
	public Long getId(Menu entity) {
		return entity.getMenuId();
	}

	/**
	 * 包含处理.
	 * 
	 * @see com.boyon.common.tree.TreeAssembly#handlerContains(java.lang.Object,
	 *      boolean)
	 */
	public void handlerContains(Menu entity, boolean isContain) {
		entity.setChecked(isContain);
		entity.setExpanded(isContain);
	}

	/**
	 * 获取父节点.
	 * 
	 * @see com.boyon.common.tree.TreeAssembly#getParent(java.lang.Object)
	 */
	public Long getParent(Menu entity) {
		return entity.getParentId();
	}

	/**
	 * 判断是否父节点.
	 * 
	 * @see com.boyon.common.tree.TreeAssembly#isParent(java.lang.Object)
	 */
	public boolean isParent(Menu entity) {
		return entity.getParentId() == 0 ? true : false;
	}

	/**
	 * 添加子节点.
	 * 
	 * @see com.boyon.common.tree.TreeAssembly#addChildren(java.lang.Object,
	 *      java.lang.Object)
	 */
	public void addChildren(Menu entity, Menu node) {
		entity.addChildren(node);
		entity.setLeaf(false);
	}

	/**
	 * 处理节点.
	 * 
	 * @see com.boyon.common.tree.TreeAssembly#handler(java.lang.Object)
	 */
	public void handler(Menu entity) {
		if (entity.getLeaf() == null) {
			entity.setLeaf(true);
		}
	}

}
